﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Reflection;
using System.Windows.Forms;

using System.IO;

using AimGameEngine.EditorObject;

namespace AimGameEngine.NodeEditorObject
{
    partial class PropretyTexture2D : Form
    {
        NodeTexture2D NodeSitting;
        public PropretyTexture2D(NodeTexture2D NodeSitting)
        {
            InitializeComponent();
            this.NodeSitting = NodeSitting;
            this.PathTexture.Text = NodeSitting.MyData.Data;
            
        }

        private void Browse_Click(object sender, EventArgs e)
        {
            OpenFileDialog file = new OpenFileDialog();
            // Default to the directory which contains our content files.
            string assemblyLocation = Assembly.GetExecutingAssembly().Location;
            string relativePath = Path.Combine(assemblyLocation, "../../../../Content");
            string contentPath = Path.GetFullPath(relativePath);

            file.InitialDirectory = contentPath;

            file.Title = "Browse Texture2D";
            // XNA support .bmp, .dds, .dib, .hdr, .jpg, .pfm, .png, .ppm, and .tga
            file.Filter = "Images Files (*.bmp;*.dds;*.dib;*.hdr;*.jpg;*.pfm;*.png;*.ppm;*.tga)|*.bmp;*.dds;*.dib;*.hdr;*.jpg;*.pfm;*.pfm;*.ppm;*.tga|" +
                          "BMP (*.bmp;*.dib)|*.bmp;*.dib|" +
                          "DDS (*.dds)|*.dds|" +
                          "Radiance (*.hdr)|*.hdr|" +
                          "JPEG (*.jpg)|*.jpg|" +
                          "Portable Bit Map (*.pfm;*.ppm;)|*.pfm;*.ppm|" +
                          "PNG (*.png)|*.png|" +
                          "Targa (*.tga)|*.tag|" +
                          "All Files (*.*)|*.*";

            file.FilterIndex = 7;

            if (file.ShowDialog() == DialogResult.OK)
            {
                this.PathTexture.Text = file.FileName;
            }
        }

        private void okButton_Click(object sender, EventArgs e)
        {
            NodeSitting.MyData.Data = this.PathTexture.Text;
        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {
            if(NodeSitting.GetImage() != null)
            e.Graphics.DrawImage(NodeSitting.GetImage(), new Point(0, 0));
        }

        private void button1_Click(object sender, EventArgs e)
        {
            NodeSitting.MyData.Data = this.PathTexture.Text;
            this.panel1.Refresh();
        }
    }
}
